package com.cgsrp.cgsrp_shopping.controller;

import com.cgsrp.cgsrp_shopping.domain.Order;
import com.cgsrp.cgsrp_shopping.domain.ShoppingCart;
import com.cgsrp.cgsrp_shopping.service.OrderService;
import com.cgsrp.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {


    @Autowired
    private OrderService orderService;


    @PostMapping("creatOrder")
    public Result creatOrder(int[] ids,Integer userId,Double totalCost){
        return orderService.creatOrder(ids,userId,totalCost);
    }

    @GetMapping("list")
    public Result list(
            @RequestParam()int userId,
            @RequestParam(defaultValue = "1")Integer curPage,
            @RequestParam(defaultValue = "5")Integer pageSize
    ){
        return orderService.list(userId,curPage,pageSize);
    }

    @PostMapping("update")
    public Result update(Order order){
        return orderService.update(order);
    }

    @PostMapping("cancel")
    public Result cancel(Long id){
        return orderService.cancel(id);
    }

    @PostMapping("confirmReceipt")
    public Result confirmReceipt(Order order,int[] creatByIds){
        return orderService.confirmReceipt(order,creatByIds);
    }


    @PostMapping("delivery")
    public Result delivery(Long orderId,Integer messageId,String trackNum){
        return orderService.deliver(orderId,messageId,trackNum);
    }

}
